<html>
<head>
<meta charset="UTF-8">
<title>服务编排首页</title>
<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">

    //获取url参数
    var subsCode=$.getUrlParam("subsCode");
    function addTab(title, url){
        if ($('#tt').tabs('exists', title)){
            $('#tt').tabs('select', title);
        } else {
            var content = '<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:99%;"></iframe>';
            $('#tt').tabs('add',{
                title:title,
                content:content,
                closable:true
            });
        }
    }

    $(function(){
		$('#nav').tree({
			url:'../../api/paas/sys/tree/nav/' + subsCode ,
			onClick: function(node){
				var parent = $('#nav').tree('getParent', node.target);
				var root = $('#nav').tree('getRoot');
				if (node.attributes.package_url) {
					addTab(parent.text + '-' + node.text, '../' + node.attributes.package_url+"&packageName="+parent.text)
				} else if (node.attributes.package_type == '41') {
					// 应用发布
					addTab(node.text, '../' + 'tdp-console/PaasAppsInfoList-SASS.html?appId=' + root.id)
				} else if (node.attributes.package_type == '42') {
					// 应用日记
					addTab(node.text, '../' + 'tdp-console/BatInstBatchList.html?subsCode=' + subsCode)
				}  else if (node.attributes.package_type == '3') {
					// 跨领域应用
					addTab(parent.text + '-' + node.text, '../' + 'tdp-console/AppModelInfoList-A00.html?appId=' + node.id)
				}
			},
			onLoadSuccess(node, data) {
				var root = $('#nav').tree('getRoot');
				$('#nav').tree('expand', root.target);
			}
		})

		reloadList();
    });
	function reloadList(){
		//修改west标题为子系统名称
		$.restfulGet('../../api/s/subs/info/' + subsCode,null,function(data){
			if (data){
				var temp= $('#cc').layout("panel","west");
				temp.panel("setTitle",data.rows.subsName);
				$("#sysName").html(data.rows.subsName)
			}
		});
		//addTab("批次信息","BatBatchInfoConfigList.html?subsCode="+subsCode);
		$("#a11").click();
	}

	function reloadTree() {
		$('#nav').tree('reload')
	}

	function onContextMenu(e, node) {
		e.preventDefault();
		$(this).tree('select',node.target);
		if (node.attributes.package_type == '1') {
			$('#mm1').menu('show',{
				left: e.pageX,
				top: e.pageY
			});
			$('#mm1').data('nodeData', node)
		} else if (node.attributes.package_type == '3') {
			$('#mm3').menu('show',{
				left: e.pageX,
				top: e.pageY
			});
			$('#mm3').data('nodeData', node)
		}

	}

</script>
</head>
<body id="cc" class="easyui-layout">
	<!-- 右侧  菜单资源树形栏 -->
	<div id="1" data-options="region:'west',title:'系统',split:true" style="width: 220px;">
		<div id="sm" data-toggle="topjui-sidemenu" data-options="data:data">
		</div>
		<div>
		<ul id="nav" class="easyui-tree"
			data-options="animate:true,
				lines:true,method:'post',
				onContextMenu: onContextMenu,
				animate:true" id="menu_app1">
		</ul>

		<!--<ul class="easyui-tree" data-options="animate:true,lines:true"
			id="menu_app1">
			<li><span><span id="sysName"></span></span>
				<ul>
						<li><span><a id="a02"
								onclick="javascript:addTab($(this).text(),'AppModelInfoInnerList.html?appId='+subsCode)"
								target="centerFrame">服务列表</a></span></li>
						<li><span>服务编排</span>
							<ul>
								<li><span><a id="a11"
											 onclick="javascript:addTab($(this).text(),'AppModelInfoList.html?appId='+subsCode)"
											 target="centerFrame">服务编排</a></span></li>
							</ul>
						</li>
						<li><span>服务发布</span>
							<ul>
								<li><span><a id="a45"
											 onclick="javascript:addTab($(this).text(),'BatInstBatchListNew.html?subsCode='+subsCode)"
											 target="centerFrame">服务发布</a></span></li>
							</ul>
						</li>
						&lt;!&ndash;
						<li><span>批次配置</span>
							<ul>
								<li><span><a id="a11"
										onclick="javascript:addTab($(this).text(),'BatBatchInfoConfigList.html?subsCode='+subsCode)"
										target="centerFrame">批次信息</a></span></li>
								<li><span><a id="a21"
										onclick="javascript:addTab($(this).text(),'BatBatchStageConfigList.html')"
										target="centerFrame">批次阶段</a></span></li>
								<li><span><a id="a23"
										onclick="javascript:addTab($(this).text(),'PluginServiceParamList.html')"
										target="centerFrame">服务参数</a></span></li>
								<li><span><a id="a12"
										onclick="javascript:addTab($(this).text(),'SSrvsCronConfList.html?subsCode='+subsCode)"
										target="centerFrame">触发配置</a></span></li>
							</ul></li>
					<li><span>批次监控</span>
						<ul>
							<li><span><a id="a45"
										 onclick="javascript:addTab($(this).text(),'BatInstBatchList.html?subsCode='+subsCode)"
										 target="centerFrame">批次监控</a></span></li>
						</ul>
					</li>
					 &ndash;&gt;
				</ul>
			</li>
		</ul>	-->
		</div>

		<div id="mm1" class="easyui-menu" style="width:120px;">
			<div onclick="appendProjectTm()" >创建领域</div>
			<div onclick="editProjectTm()" >修改领域</div>
			<div onclick="viewProjectTm()" >查看领域</div>
			<div onclick="removeProjectTm()" >删除领域</div>
		</div>
		<div id="mm3" class="easyui-menu" style="width:120px;">
			<div onclick="appendApp()" >创建跨领域编排应用</div>
			<div onclick="editApp()" >修改跨领域编排应用</div>
			<div onclick="viewApp()" >查看跨领域编排应用</div>
			<div onclick="removeApp()" >删除跨领域编排应用</div>
		</div>
	</div>
	<!-- 中间  内容主体 -->
	<div data-options="region:'center',border:false" title="" style="padding: 0px; background: #eee;">
		<!-- 资源操作 start -->
		<div class="easyui-panel" data-options="region:'center', border:'false'" style="height:95%">

			<div id="tt" class="easyui-tabs" fit="true" border="false" >
			</div>

		</div><!-- 资源操作 end -->
	</div>
	<script type="text/javascript">
		// src/main/webapp/page/esaas-dmcenter/ProjectTmInfoAdd.html
		function appendProjectTm() {
			let nodeData = $('#mm1').data('nodeData')
			JLEUtil.createModalWin('新增', '../esaas-dmcenter/ProjectTmInfoAdd.html?packageId=' + nodeData.id + '&packageType=' + nodeData.attributes.package_type);
		}
		function editProjectTm() {
			let nodeData = $('#mm1').data('nodeData')
			// 不是模型下子节点 不打开页面
			if (!nodeData.attributes.package_url) {
				return
			}
			JLEUtil.createModalWin('新增', '../esaas-dmcenter/ProjectTmInfoUpdate.html?projectId=' + nodeData.id );
		}
		function viewProjectTm() {
			let nodeData = $('#mm1').data('nodeData')
			// 不是模型下子节点 不打开页面
			if (!nodeData.attributes.package_url) {
				return
			}
			JLEUtil.createModalWin('新增', '../esaas-dmcenter/ProjectTmInfoView.html?projectId=' + nodeData.id );
		}
		function removeProjectTm() {
			let nodeData = $('#mm1').data('nodeData')
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"packageId":"' + nodeData.id + '"'+'}');
					$.restfulDelete('../../api/paas/sys/tree', jsonData, function(data) {
						// 删除 model_table_info project_tm_info
						$.restfulDelete('../../api/project/tm/info/withtb', { projectId : nodeData.id})
						$.messager.alert('提示','记录删除成功!','info');
						reloadTree()
					});
				}
			});
		}

		function appendApp() {
			let nodeData = $('#mm3').data('nodeData')
			JLEUtil.createModalWin('新增', 'PaasAppsInfoAdd.html?packageId=' + nodeData.id + '&packageType=' + nodeData.attributes.package_type);
		}

		function editApp() {
			let nodeData = $('#mm3').data('nodeData')
			JLEUtil.createModalWin('新增', 'PaasAppsInfoUpdate.html?packageId=' + nodeData.id + '&packageType=' + nodeData.attributes.package_type);
		}

		function viewApp() {
			let nodeData = $('#mm3').data('nodeData')
			JLEUtil.createModalWin('新增', 'PaasAppsInfoView.html?packageId=' + nodeData.id + '&packageType=' + nodeData.attributes.package_type);
		}
		function removeApp() {
			let nodeData = $('#mm3').data('nodeData')
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"packageId":"' + nodeData.id + '"'+'}');

					$.restfulDelete('../../api/paas/sys/tree', jsonData, function(data) {
						// 删除 paas_sys_info
						$.restfulDelete('../../api/paas/apps/info', { appId : nodeData.id}, function() {
							$.messager.alert('提示','记录删除成功!','info');
							reloadTree()
						});
					});
				}
			});
		}


	</script>
</body>
</html>
